Allow setting a displayName for wrapper component created in renderHook#1396
Allow setting a displayName for wrapper component created in renderHook#1396vikr01 wants to merge 2 commits intotesting-library:mainfrom vikr01:main
Conversation
|
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 443834a:
|
|
Thanks for this. |
|
For hooks that use the internal fiber nodes, such as https://github.com/pmndrs/its-fine, when you check the react tree, you'd want to see a name you're familiar with otherwise it's just going to be https://github.com/pmndrs/its-fine/blob/main/src/index.test.tsx#L146 In my specific use case, I'm creating a hook that gives you a string that is unique to the structure of an element, so that you can restore values based on its position (i.e. after suspending). So in this scenario, I want this actual displayName string because the pointer for the component is destroyed. So yes, it is something you would want to assert on, but you can only assert on it if you're able to reach the component by attempting to see the element tree. |
|
I understand the use case but I'm honestly not sure we'd want to provide this because it may cause bad testing patterns. @eps1lon wdyt? |
There was a problem hiding this comment.
The function is named so I don't understand why you'd need to override the displayName since React will already display a name. renderHook is just a convenience helper and doesn't need all possible configuration options. Especially if it's to support libraries that rely on React internals and contribute to forking the ecosystem
If you need a special displayName, you can write your own wrapper.
|
That's fair, technically it is named. |
What:
renderHookcreates, you can (i.e.console.log,useFiber,ReactCurrentOwner)Why:
How:
Checklist:
docs site